package com.ithiem.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.dubbo.api.BlackListApi;
import com.itheima.model.domain.BlackList;
import com.itheima.model.domain.UserInfo;
import com.ithiem.dubbo.mappers.BlackListMapper;
import com.ithiem.dubbo.mappers.UserInfoMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class BlackListApiImpl implements BlackListApi {

    @Autowired
    private BlackListMapper blackListMapper;
    @Autowired
    private UserInfoMapper userInfoMapper;
    /*分页查询黑名单*/
    @Override
    public IPage<UserInfo> pageList(Long userId, int page, int pagesize) {
        Page<UserInfo> userInfoPage = new Page<>(page,pagesize);
        IPage<UserInfo> iPage= userInfoMapper.pageBlackList(userInfoPage,userId);
        return iPage;
    }
//    移出黑名单
    @Override
    public void delete(Long userId, Long blackUserId) {
        LambdaQueryWrapper<BlackList> lqw = new LambdaQueryWrapper<>();
        lqw.eq(BlackList::getBlackUserId,blackUserId).eq(BlackList::getUserId,userId);
        blackListMapper.delete(lqw);
    }
}
